Page({
  data: {
    hotCourses: []  // 热门课程数据
  },

  onLoad() {
    this.loadHotCourses();
  },

  // 加载热门课程
  loadHotCourses() {
    wx.request({
      url: 'http://localhost:8080/admin/courses/hotCourses',
      method: 'GET',
      success: (res) => {
        if (res.data.code === 200 && res.data.data.list) {
          // 只取前6个课程
          const hotCourses = res.data.data.list.slice(0, 6);
          this.setData({ hotCourses });
        }
      }
    });
  },

  // 跳转到课程详情
  goToCourseDetail(e) {
    const courseId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/kecheng_detail/kechengxiangqing/kechengxiangqing?id=${courseId}`
    });
  }
}); 